package com.wxq.cart.vo;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author Jim
 * @date 1:13 下午 2022/4/21
 * @description 购物车
 * @email:huwmz04153277@126.com
 */
public class CartVO {
    private List<CartItemVO> items;

    private Integer countNum;

    private Integer countType;

    private BigDecimal totalAmount;

    private BigDecimal reduce;

    public CartVO(){
        reduce = new BigDecimal("0");
    }

    public List<CartItemVO> getItems(){
        return items;
    }

    public void setItems(List<CartItemVO> items) {
        this.items = items;
    }

    /**
     * 计算商品总数量
     * @return
     */
    public Integer getCountNum() {
        int count = 0;
        if (items != null && items.size() > 0){
            for (CartItemVO item : items) {
                count += item.getCount();
            }
        }
        return count;
    }

    public void setCountNum(Integer countNum) {
        this.countNum = countNum;
    }

    /**
     * 计算商品类型数量
     * @return
     */
    public Integer getCountType() {
        int count = 0;
        if (items != null && items.size() > 0){
            for (CartItemVO item : items) {
                count += 1;
            }
        }
        return count;
    }

    public void setCountType(Integer countType) {
        this.countType = countType;
    }

    /**
     * 计算商品总金额
     * @return
     */
    public BigDecimal getTotalAmount() {
        BigDecimal amount = new BigDecimal("0");
        //计算购物项总价
        if (items != null && items.size() > 0){
            for (CartItemVO item : items) {
                BigDecimal totalPrice = item.getTotalPrice();
                amount = amount.add(totalPrice);
            }
        }
        //减去优惠总价
        amount = amount.subtract(getReduce());
        return amount;
    }

    public void setTotalAmount(BigDecimal totalAmount) {
        this.totalAmount = totalAmount;
    }

    public BigDecimal getReduce() {
        return reduce;
    }

    public void setReduce(BigDecimal reduce) {
        this.reduce = reduce;
    }
}
